package CSDN;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 王圆豪
 * Date: 2025-05-08
 * Time: 10:46
 */
public class Test17 {
    public static void main(String[] args) {
        Object l1 = new Object();
        Thread t1 = new Thread(()->{
            synchronized (l1){
                try {
                    l1.wait();
                    System.out.println("t1被唤醒！");
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        Thread t2 = new Thread(()->{
            synchronized (l1){
                try {
                    l1.wait();
                    System.out.println("t2被唤醒！");
                }    catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        Thread t3 = new Thread(()->{
            synchronized (l1){
                try {
                    l1.wait();
                    System.out.println("t3被唤醒！");
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });
        Thread t4 = new Thread(()->{
            System.out.println("输入任意内容唤醒所有线程：");
            Scanner sc = new Scanner(System.in);
            sc.next();
            synchronized (l1){
                l1.notifyAll();
            }
        });

        t1.start();
        t2.start();
        t3.start();
        t4.start();
    }
}
